package com.ctshk.sapp.goods.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.goods.dto.FreightTemplateDTO;
import com.ctshk.rpc.goods.req.FreightTemplateAddReq;
import com.ctshk.rpc.goods.req.FreightTemplatePageReq;
import com.ctshk.rpc.goods.service.IFreightTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 运费模板表 前端控制器
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-09
 */
@Api(value="运营中心-运费模板", tags="运营中心-运费模板")
@RestController
@RequestMapping("/freight/template")
public class FreightTemplateController extends BaseController {
	
	@DubboReference
    private IFreightTemplateService templateService;

    @ApiOperation(value = "新增运费模板", notes = "新增运费模板")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "新增运费模板", operDesc = "新增运费模板")
    @PostMapping("/addFreightTemplate")
    public Result addFreightTemplate(@RequestBody @Valid FreightTemplateAddReq obj) throws Exception {
    	templateService.addFreightTemplate(obj, getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value = "编辑运费模板", notes = "编辑运费模板")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "编辑运费模板", operDesc = "编辑运费模板")
    @PostMapping("/updateFreightTemplate")
    public Result updateFreightTemplate(@RequestBody @Valid FreightTemplateAddReq obj) throws Exception {
    	templateService.updateFreightTemplate(obj,getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value = "刪除运费模板", notes = "刪除运费模板")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.DELETE, operTitle = "刪除运费模板", operDesc = "刪除运费模板")
    @PostMapping("/deleteFreightTemplate")
    public Result deleteFreightTemplate(@RequestBody @Valid FreightTemplateAddReq obj) throws Exception {
    	templateService.deleteFreightTemplate(obj,getCurrentUser(getRequest()).getId());
        return Result.success();
    }
    
    @ApiOperation(value = "分页查询运费模板管理", notes = "分页查询运费模板管理")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "分页查询运费模板管理", operDesc = "分页查询运费模板管理")
    @PostMapping("/findPageList")
    public Result<PageResponse<FreightTemplateDTO>> findPageList(@RequestBody FreightTemplatePageReq pageReq) {
        PageResponse<FreightTemplateDTO> response = templateService.findFreightTemplate(pageReq,getCurrentUser(getRequest()));
        return Result.success(response);
    }

    @ApiOperation(value = "查询运费模板下拉列表", notes = "查询运费模板下拉列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询运费模板下拉列表", operDesc = "查询运费模板下拉列表")
    @GetMapping("/findClassificationTemplateList")
    public Result<List<FreightTemplateDTO>> findClassificationTemplateList() {
        List<FreightTemplateDTO> response = templateService.findClassificationTemplateList();
        return Result.success(response);
    }

    @ApiOperation(value = "根据ID查询运费模板详情", notes = "根据ID查询运费模板详情")
    @OperationLogAnnotation(operModul = OperationLogModel.GOODS, operType = OperationLogType.QUERY, operTitle = "根据ID查询运费模板详情", operDesc = "根据ID查询运费模板详情")
    @GetMapping("/findFrightTemplateInfoById/{id}")
    public Result<FreightTemplateDTO> findFrightTemplateInfoById(@PathVariable("id") Long id) {
        FreightTemplateDTO response = templateService.findFrightTemplateInfoById(id);
        return Result.success(response);
    }

    /*
    * 本地測試
    @ApiOperation(value = "提供内部接口（查询运费符合情况  如：根据件，重量查询出来价格）", notes = "提供内部接口（查询运费符合情况  如：根据件，重量查询出来价格）")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "提供内部接口（查询运费符合情况  如：根据件，重量查询出来价格）", operDesc = "提供内部接口（查询运费符合情况  如：根据件，重量查询出来价格）")
    @PostMapping("/getFreightByWeightOrPieceCount")
    public JSONObject getFreightByWeightOrPieceCount(@RequestBody FreightTemplateAddReq obj) {
        return templateService.getFreightByWeightOrPieceCount(obj.getId(), obj.getFirstArticles(), obj.getRegionId());
    }
    */
}
